package com.itheima.controller;

import com.itheima.entity.Clazz;
import com.itheima.entity.ClazzQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam){
        log.info("分页查询班级信息，参数：{}", clazzQueryParam);
        PageBean pageBean = clazzService.page(clazzQueryParam);
        return Result.success(pageBean);
    }

    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        log.info("新增班级，参数：{}", clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询班级信息，参数：{}", id);
        Clazz clazz = clazzService.getInfo(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息，参数：{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级信息，参数：{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }
}
